import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
//导入路由
import Notice from '../components/console/notice.vue'
import Personal from '../components/console/personal.vue'
import Sing_up from '../components/console/sign_up.vue'
import Studio_members from '../components/console/studio_members.vue'
import Studio from '../components/console/studio.vue'
import Login from '../components/console/login.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/login'
  },
  { path:'/login',component:Login},
  {
    path: '/home',
    component:Home,
    redirect:'/studio',
    children:[
      //公告
      {path:'/notice',component:Notice},
      //个人
      {path:'/personal',component:Personal},
      //报名
      {path:'/sign_up',component:Sing_up},
      //工作室成员
      {path:'/studio_members',component:Studio_members},
      //工作室
      {path:'/studio',component:Studio}
    ]
  }
]


const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  if (to.path === '/login'){
    next();
  }else{
    let tokens = sessionStorage.getItem('token');
    if(!tokens){
      next('/login')
    }else{
      next();
    }
    
  }
})
export default router
